<template>
  <div class="work">

    <!-- 搜索框 -->
    <div class="search">
          <div class="title">
            Certification Management
          </div>
          <div class="dateSearch">
          <div>
            <el-date-picker
                v-model="form.startTime"
                type="month"
                value-format='yyyy-MM'
                :picker-options="startTime"
                placeholder="start time">
            </el-date-picker>
            <el-date-picker
                v-model="form.endTime"
                type="month"
                value-format='yyyy-MM'
                :picker-options="endTime"
                placeholder="end time">
            </el-date-picker>
          </div>
          <div>
            <el-button type="info" plain @click="search" style="border-radius:0">search</el-button>
            <el-button type="info" plain @click="clearSearch" style="margin-left:0;border-radius:0">cancel search</el-button>
          </div>
      </div>
    </div>

    <!-- 主体内容 -->
    <template>
      <el-table
          :header-cell-style="{background:'#F2F6FC',color:'#606266'}"
          :data="tableData"
          border
          style="width: 100%"
          ref="tableData"
          class="emp_table"
          v-if="tableData">
          <el-table-column label="S/N" type="index" width="60" align="center"></el-table-column>
          <el-table-column
          align="center"
          prop="payment_voucher_id"
          label="No"
          width="180">
          </el-table-column>
          <el-table-column
          align="center"
          prop="payment_voucher_name"
          label="name">
          </el-table-column>
          <el-table-column
          align="center"
          prop="pe_name"
          label="Prepared by">
          </el-table-column>
          <el-table-column
          align="center"
          prop="created"
          label="Generated date">
          </el-table-column>
          <el-table-column
          align="center"
          prop="status_name"
          label="Status">
          <template slot-scope="{ row }">
            {{ row.status_name }}
          </template>
          </el-table-column>
        <el-table-column
          align="center"
          label="Action">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="see(scope.row.payment_voucher_id)">see details</el-button>
            </template>
          </el-table-column>
      </el-table>
    </template>

    <!--分页-->
    <el-pagination
      align="right"
      @current-change="curChange"
      :current-page.sync="curPage"
      :page-size="10"
      layout="total,prev, pager, next, jumper"
      :total="count">
    </el-pagination>

    <!-- <seeForm ref="seeForm"></seeForm> -->

  </div>


</template>

<script>
import {seePayment} from "@/request/other_api"
import {sendEmail} from "@/request/api"

// import seeForm from "./seeForm";

export default {
    components:{
    // seeForm,
  },
  data() {
    return {
        // 搜索内容
        searchName:'',
        // 页面数据
        tableData: [],
        // count:总数据量
        count:0,
        // 当前页
        curPage:1,
        // 弹出框是否可见
        dialogVisible: false,
        // 等级
        level:'',
        // 是否在搜索状态
        isSearch:false,
        key:Number,
        //搜索时间
        form:{
          startTime:undefined,
          endTime:undefined,
        },
        startTime: {
          disabledDate: time => {
            let endDateVal = this.form.endTime;
            if (endDateVal) {  return time.getTime() > new Date(endDateVal).getTime()}
          }
        },
        endTime: {
          disabledDate: time => {
            let beginDateVal = this.form.startTime;
            if (beginDateVal) { return time.getTime() < new Date(beginDateVal).getTime()}
          }
        },
    }
  },
  mounted () {
    this.level = sessionStorage.getItem('level')
  },
  created() {
    //获取初始列表数据
    seePayment({
      key:1
    }).then(res => {
      if(res.code == 200){
        this.count = res.count
        this.tableData = res.data
      }
    })
  },
  methods: {
    //获取支付凭证列表
    seePaymentList(){
      seePayment({
        key:1
      }).then(res => {
        if(res.code == 200){
          this.count = res.count
          this.tableData = res.data
        }
      })
    },
    // 搜索
    search(){
      this.isSearch = true
      seePayment({
        key:1,
        startDate:this.form.startTime,
        endDate:this.form.endTime,
      }).then(res => {
        this.count = res.count
        this.tableData = res.data
      })
      this.curPage = 1
    },
    // 取消搜索
    clearSearch(){
      this.isSearch = false
      seePayment({
        key:1
      }).then(res => {
        if(res.code === 200){
            this.count = res.count
            this.tableData = res.data
        }
      })
      this.curPage = 1
      this.form.startTime=''
      this.form.endTime=''
    },
    //查看支付凭证详情
    see(payment_voucher_id){
      let routeData = this.$router.resolve(`/paymentDetail/${payment_voucher_id}`)
      window.open(routeData.href, '_blank')
    },
    /**
     * 分页
     */
    //  点击每页刷新获取数据
    curChange (page) {
      this.curPage = page
      if(this.isSearch) {
        this.seePaymentSearchPageList()
      } else {
        this.seePaymentPageList()
      }
    },
    // 上一页
    prevClick () {
    this.curPage < 1 ? this.curPage = 1 : this.curPage--
      if(this.isSearch) {
        this.seePaymentSearchPageList()
      } else {
        this.seePaymentPageList()
      }
    },
    // 下一页
    nextClick () {
    this.curPage >= this.count ? this.curPage = this.count : this.curPage++
      if(this.isSearch) {
        this.seePaymentSearchPageList()
      } else {
        this.seePaymentPageList()
      }
    },
    //获取搜索列表分页
    seePaymentSearchPageList(){
      seePayment({
        key:1,
        page: this.curPage,
        keyword:this.searchName,
      }).then(res => {
        this.count = res.count
        this.tableData = res.data
      })
    },
    //获取已有报销单列表分页
    seePaymentPageList(){
      seePayment({
        key:1,
        page: this.curPage,
      }).then(res => {
        if(res.code === 200){
          this.count = res.count
          this.tableData = res.data
        }
      })
    },
  },
}
</script>

<style lang="less">
    .search {
      display: flex;
      justify-content: space-between;
      padding-bottom: 20px;
    }
    .dateSearch {
      display: flex;
      justify-content: space-between;
      padding-bottom: 0px;
      border-radius:0
    }
    .permitImg{
      width: 35px;
      height: 35px;
    }
    .dig-form{
      width: 90%;
      height: 100%;
      margin: 0 auto;
    }
    .preImg{
      width:56px;
      border-radius:4px;
      height:40px;
      margin-right:15px
    }
    .title{
      font-family: SourceHanSansSC;
      font-weight: 700;
      font-size: 20px;
      color: rgb(16, 16, 16);
      font-style: normal;
      letter-spacing: 0px;
      line-height: 30px;
      text-decoration: none;
      margin-bottom: 10px;
    }
</style>


